<%@ page import="cn.jcenterhome.service.DataBaseService" %>
<%@ page import="cn.jcenterhome.util.BeanFactory" %>
<%@ page import="cn.jcenterhome.util.Common" %>
<%@ page import="cn.jcenterhome.util.JavaCenterHome" %>
<%@ page import="java.util.*" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 12-12-6
  Time: 下午5:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>充值码生成器</title>
    <style type="text/css">
        @import url(template/default/style.css);
        @import url(template/default/gift.css);
    </style>
</head>
<body>
<%DataBaseService dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");%>
<table width="100%" border="0">
<tr>
    <td>
	<form id="createCode" name="CreateCode" action="?uid=<%=Common.rand(10)%>" method="post"><fieldset><legend>生成充值码:</legend>
	    <select name="inputMoney">
          <option value="2000" selected>20元</option>
          <option value="3000">30元</option>
          <option value="5000">50元</option>
          <option value="10000">100元</option>
          <option value="20000">200元</option>
          <option value="50000">500元</option>
        </select>
	    <label>
	    <input type="submit" name="Submit2" value="生成">
		<%String money=request.getParameter("inputMoney");
		if(money!=""&&money!=null)
        {
            dataBaseService = (DataBaseService) BeanFactory.getBean("dataBaseService");
            String uuid = UUID.randomUUID().toString();
            Map<String, Object> recharge = new HashMap<String, Object>();
            recharge.put("rechargecode",uuid);
            recharge.put("rechargemoney",Common.intval(money));
            dataBaseService.insertTable("recharge",recharge,true,false);
        }
        %>
	    </label>
	</fieldset>
	</form>	</td>
  </tr>
  <tr>
    <td>
	<form method="post" name="selectFrom" action="?<%=Common.rand(10)%>">
	充值者姓名：
    
      <input type="text" name="username">
    充值卡号：
    <input type="text" name="carcode">
    充值卡金额：
    <select name="selectMoney">
      <option value="2000" selected>20元</option>
      <option value="3000">30元</option>
      <option value="5000">50元</option>
      <option value="10000">100元</option>
      <option value="20000">200元</option>
      <option value="50000">500元</option>
    </select>
    使用状态：
    <select name="status">
      <option value="1">已使用</option>
      <option value="0" selected>未使用</option>
    </select>
   
	  <input type="submit" name="Submit" value="查询">
	  <a href="#?<%=Common.rand(10)%>" target="_self">查看全部</a>
	</form>	</td>
  </tr>
    <%

        String selectMoney= request.getParameter("selectMoney");
        String username = request.getParameter("username");
        String carCode =request.getParameter("carCode");
        String status = request.getParameter("status");
        String cSQL = "SELECT COUNT(*) FROM " + JavaCenterHome.getTableName("recharge")+" where 1=1 ";
        String SQL = "SELECT * FROM " + JavaCenterHome.getTableName("recharge")+" where 1=1 ";
        StringBuilder where= new StringBuilder();

        if(!Common.empty(carCode))
        {
            where.append( "and rechargecode='"+carCode+"'");
        }else if(!Common.empty(username))
        {
        where.append( "and username='"+username+"'");
        }else if(!Common.empty(selectMoney))
        {
        where.append( "and rechargemoney='"+selectMoney+"'") ;
        }else if(!Common.empty(status))
        {
        where.append( "and status='"+status+"'")   ;
        }
        int perPage = 2;  //每页显示数据条数
        int pagenum= Common.intval(request.getParameter("page"));
        int maxPage =100;
        pagenum = pagenum <= 1 ? 1 : pagenum;
        int start = (pagenum - 1) * perPage;
        int count =  dataBaseService.findRows(cSQL+where.toString());
        List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
        String multi = "";
        if(count>0)
        {
        multi=Common.multi(request, count, perPage, pagenum, maxPage, "ecardXXvMMQdsFfrSk.jsp",null, null);
        request.setAttribute("multi",multi);
        list = dataBaseService.executeQuery(SQL+where.toString() + " LIMIT " + start + "," + perPage);
        request.setAttribute("list1",list);
        System.out.println("list.size()="+list.size());
        }
    %>
  <tr>
    <td height="110" align="left" valign="top"><table width="100%" border="0">
      <tr>
        <td>充值码</td>
        <td>金额</td>
        <td>使用时间</td>
        <td>创建时间</td>
        <td>用户id</td>
        <td>用户名</td>
        <td>状态</td>
      </tr>
      <c:forEach items="${list1}" var="value" varStatus="key">
      <tr>
        <td>${value.rechargecode}</td>
        <td>${value.rechargemoney/100}</td>
        <td>${value.usedate}</td>
        <td>${value.createtime}</td>
        <td>${value.userid}</td>
        <td>${value.username}</td>
        <td>${value.status==0?"未使用":"已经使用"}</td>
      </tr>
      </c:forEach>
    </table></td>
  </tr>
</table>
<div class="page">${multi}</div>
</body>
</html>